
set(PROJECT_NAME "nosal-exec-execution-client")

add_library(target-execution-client STATIC
    ${CMAKE_CURRENT_LIST_DIR}/execution_client.cpp
    ${CMAKE_CURRENT_LIST_DIR}/exec_error_domain.cpp
)

target_include_directories(target-execution-client
PUBLIC
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
PRIVATE
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)

target_link_libraries(target-execution-client
PUBLIC
    nosal::core
PRIVATE
    nosal::log
    $<BUILD_INTERFACE:target-objects-common>
)

# Create *.pc file
if(PKG_CONFIG_FOUND)
    set(LIBRARIES "-lnosal_exec_execution_client")
    configure_file(${PROJECT_SOURCE_DIR}/files/pkgconfig/nosal-exec.pc.in nosal-exec-execution-client.pc @ONLY)
    install(
        FILES ${CMAKE_CURRENT_BINARY_DIR}/nosal-exec-execution-client.pc
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
    )
endif()

# Create *-config.cmake file
configure_package_config_file(
    ${PROJECT_SOURCE_DIR}/files/cmake/nosal-exec-config.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/nosal-exec-execution-client-config.cmake
    INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nosal-exec-execution-client
    NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Create *-config-version.cmake file
write_basic_package_version_file(
    ${CMAKE_CURRENT_BINARY_DIR}/nosal-exec-execution-client-config-version.cmake
    COMPATIBILITY ExactVersion
)
# Install *-config.cmake and *-version.cmake files
install(
    FILES
        ${CMAKE_CURRENT_BINARY_DIR}/nosal-exec-execution-client-config.cmake
        ${CMAKE_CURRENT_BINARY_DIR}/nosal-exec-execution-client-config-version.cmake
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nosal-exec-execution-client
)

set(EXECUTION_CLIENT_PUBLIC_HEADERS
    ${PROJECT_SOURCE_DIR}/include/nosal/exec/execution_client.h
    ${PROJECT_SOURCE_DIR}/include/nosal/exec/exec_error_domain.h
)

set_target_properties(target-execution-client PROPERTIES
    OUTPUT_NAME nosal_exec_execution_client
    PUBLIC_HEADER "${EXECUTION_CLIENT_PUBLIC_HEADERS}"
    EXPORT_NAME exec_execution_client
)

install(
    TARGETS target-execution-client
    EXPORT target-export-execution-client
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nosal/exec
)

install(
    EXPORT target-export-execution-client
    DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/nosal-exec-execution-client
    NAMESPACE nosal::
    FILE nosal-exec-targets.cmake
)
